package 动态规划.斐波那契数;

/**
 * @author: wh(1835734390 @ qq.com)
 * @date: 2023/2/7 21:06
 * @description:
 * @version:
 */
public class Solution {
    public static void main(String[] args) {
        System.out.println(fib(4));
    }

    //递归效率低，有可能超出时间限制
    public static int fib(int n) {
        if (n == 0 || n == 1){
            return n;
        }
        return fib(n-1)+fib(n-2);
    }

    public static int fib2(int n) {
        if(n == 0) return 0;
        int[] dp = new int[n + 1];
        dp[0] = 0;
        dp[1] = 1;
        for(int i = 2; i <= n; i++){
            dp[i] = dp[i-1] + dp[i-2];
            dp[i] %= 1000000007;
        }
        return dp[n];
    }
}
